package com.itqian.configuration;

import com.itqian.interceptors.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shishuqian
 * date 2022/3/28
 * time 17:13
 * 注册拦截器
 **/
@Configuration
public class JWTConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> excludeList = new ArrayList<>();
        //获取验证码
        excludeList.add("/user/getCode/**");
        //注册
        excludeList.add("/user/register");
        //账号密码登录
        excludeList.add("/user/login");
        //手机号登录
        excludeList.add("/user/phoneLogin");

        excludeList.add("/user/**");

        excludeList.add("/admin/order/export/**");

        registry.addInterceptor(new JWTInterceptor())
                //拦截的资源路径
                .addPathPatterns("/**")
                //不拦截的资源路径
                .excludePathPatterns(excludeList)
                //swagger相关
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
    }


}
